/*
 * @brief:
 * @Author: TzzzT
 * @Date: 2022-05-10 13:59:22
 * @LastEditTime: 2023-05-03 22:54:59
 * @LastEditors: TzzzT
 */
#pragma once
#include "RCS_master.h"
#include "stdio.h"
#include "stdlib.h"

/**
 * @brief
 * 基站的储存用两种数据结构，
 * 对于单一型的基站，只要处于范围中就足够，不需要知道基站id类型的，采用数组保存，方便查找
 * 对于需要知道具体id的基站，采用链表保存，方便动态储存多个此类型的基站。
 */
typedef enum station_state_e
{
    KEEP_NO,
    RISE,
    KEEP_HOLD,
    DOWN,
} station_state_t;

typedef struct station_node_s
{
    int16_t avg_rssi;
    uint8_t count;
    uint32_t id;
    struct station_node_s *next_node;
} station_node_t;
//  __attribute__((packed))
typedef struct station_list_head_s
{
    station_node_t *fake_head;
} station_list_t;

// array item
typedef struct station_item_s
{
    int16_t avg_rssi;
    uint8_t count;
    station_state_t st;
} station_item_t;

void set_allow_open(bool st);
bool is_allow_open_ble_server(void);

void set_allow_scan_new_slave_flag(bool st);
// set bda是设置底层驱动的bda
void rcs_set_remote_bda(uint8_t equip_sn, bd_addr_t remote_bda);
bool rcs_try_to_open_server(uint8_t equip_sn);
void rcs_close_all_connection(uint8_t equip_sn);
void rcs_try_to_scanning(uint32_t scan_time);
void rcs_stop_scan_server(void);
esp_err_t rcs_send_to_bleserver(uint8_t equip_sn, uint8_t *package, uint16_t package_len);
void ble_mast_init(void);
void ble_remember_last_server(void);

void init_station_list(void);
void update_uni_station(void);
void update_dynamic_sta_list(dynamic_sta_type_t idx);
int16_t set_station_rssi(int16_t old_value, int8_t rssi);
void select_team(void);
void station_hp_handle(void);
void station_reborn_handle(void);
void station_occupy_handle(uint8_t state);
void period_dynamic_station_handle(dynamic_sta_type_t idx);
void station_invincible_handle(void);
